#pragma once

#include <QtWidgets/QMainWindow>
#include "ui_QFtpDownloader.h"
#include "qftp.h"

#include <qlist.h>
#include <qfile.h>

class QFtpDownloader : public QMainWindow
{
    Q_OBJECT
private slots:
    void on_pushButton_list_clicked();
    void on_pushButton_upload_clicked();
    void on_pushButton_download_clicked();
    void on_pushButton_continue_clicked();
    void on_pushButton_pause_clicked();
    void on_toolButton_upload_clicked();
    void on_toolButton_download_clicked();
    

    void OnDataTransferProgress(qint64, qint64);
    void OnCommandFinished(int, bool);
    void OnStateChanged(int);
    void OnListInfo(const QUrlInfo&);
public:
    explicit QFtpDownloader(QWidget *parent = Q_NULLPTR);
    ~QFtpDownloader();
   
protected:
    void OnInitDialog();
private :
    void InitFtp();
    bool InitFtpConnect(const QString& host, quint16 port, const QString& username, const QString& password);
    void ListImplement(const QString&);
    QString GetLocalFileName();
    void my_sleep(unsigned int interval);//interval*50 (millseconds)
    void ReleaseFile();
    bool JudgeFileExist();
    void InitProcessBar()noexcept;
private:
    Ui::QFtpDownloaderClass ui;
    QFtp* m_ftp;
    QFtp::State m_state;
    QString m_user_name;
    QString m_password;
    QList<QUrlInfo>m_remote_files;
    QFile* m_file;
};
